package inc.gome.dynamic.datasource.config;

import inc.gome.dynamic.datasource.loader.EnhancedServiceLoader;
import inc.gome.dynamic.datasource.utils.CollectionUtils;

import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * @author sujizhou
 * @Date 2021/12/15
 * @Desc 读取配置类文件
 */
public class TestReadFileConfig {

    private static final ConcurrentMap<String, String> SERVICE_LOADERS =
            new ConcurrentHashMap<>();


    public static void main(String[] args) {
        String registryTypeName = ConfigurationFactory.CURRENT_FILE_INSTANCE.getConfig(
                ConfigurationKeys.FILE_ROOT_REGISTRY + ConfigurationKeys.FILE_CONFIG_SPLIT_CHAR
                        + ConfigurationKeys.FILE_ROOT_TYPE);

        System.out.println(registryTypeName);

//        //返回存在的
//        String abc1 = CollectionUtils.computeIfAbsent(SERVICE_LOADERS, "abc", key -> "123");
//        String abc2 = CollectionUtils.computeIfAbsent(SERVICE_LOADERS, "abc", key -> "1234");
//        System.out.println(abc1);
//        System.out.println(abc2);
//
//
//        ConfigurationCache.addConfigListener("transport" + ConfigurationKeys.FILE_CONFIG_SPLIT_CHAR
//                + ConfigurationKeys.FILE_ROOT_TYPE);
//
//        Configuration instance = ConfigurationFactory.getInstance();




//        new Thread(()->{
//
//            while(true) {
//                try {
//                    Thread.sleep(2000);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//                String config = instance.getConfig("transport" + ConfigurationKeys.FILE_CONFIG_SPLIT_CHAR
//                        + ConfigurationKeys.FILE_ROOT_TYPE);
//                System.out.println(config);
//            }
//        }).start();

        try {
            System.in.read();
        } catch (IOException e) {
            e.printStackTrace();
        }


/*        Configuration configuration = new FileConfiguration("registry");
        configuration = ConfigurationCache.getInstance().proxy(configuration);
        configuration.getBoolean("aaa", false);

        //缓存内存更新
        ConfigurationCache.getInstance().onChangeEvent(new ConfigurationChangeEvent("aaa", "true"));


        System.out.println(configuration.getBoolean("aaa", false));*/


    }
}
